<template>
	<view>
		<!-- 搜索框 -->
		
		<!-- 分段器 -->
		<u-subsection :list="list" :current="curNow" @change="sectionChange" activeColor="#62ab65"></u-subsection>
		<view>
			<view v-show="curNow === 0" style="width: 90%;height:100%; margin: 0 auto;margin-top: 15rpx;">
				<view v-for="i in fwd1">
					<uni-card :title="i.submitter+'上传的文档'" style="border-radius: 15px;" @click="wdtz(i.archivesname)">
						<view style="float: left;width: 15px;margin-top: 2px;">
							<u-icon name="file-text"></u-icon>
						</view>
						<view style="float: left; width: 350rpx;">
							<u--text type="info" :size="12" style="float: left;width: 250px;"
								:text="i.submitter+'于'+aa(i.subtime)+'上传'">
							</u--text>
							<u--text type="info" :size="12" style="float: left;width: 250px;" text="点击预览pdf文件">
							</u--text>
						</view>
					</uni-card>
				</view>

			</view>
			<view v-show="curNow === 1" @click="findMyWd()" style="width: 90%;height:100%; margin: 0 auto;margin-top: 15rpx;">
					<view v-for="(i,index) in mywd" :key="index">
						<uni-card :title="i.submitter+'上传的文档'" style="border-radius: 15px;"
							@click="wdtz(i.archivesname)">
							<view style="float: left;width: 15px;margin-top: 2px;">
								<u-icon name="file-text"></u-icon>
							</view>
							<view style="float: left; width: 350rpx;">
								<u--text type="info" :size="12" style="float: left;width: 250px;"
									:text="i.submitter+'于'+aa(i.subtime)+'上传'">
								</u--text>
								<u--text type="info" :size="12" style="float: left;width: 250px;" text="点击预览pdf文件">
								</u--text>
							</view>
						</uni-card>
					</view>
					<u-popup :show="show" :round="20" @close="close" @open="open">
						<view>
							<view style="width: 100%;height: 50px;">
								<text style="float: left;margin:15px 0px 0px 125px;color:#a4a09c ;">请选择PDf格式文件</text>
							</view>
							<view>
								<l-file ref="lFile" @up-success="onSuccess"></l-file>
								<button @tap="onUpload">上传</button>
								<!-- 	<u-button @click="openFile" class="butt1" type="success" shape="circle">
									上传文件
								</u-button> -->
							</view>

							<view @click="close">
								<u-button class="butt1" style="color: #a7a19c;" type="success" shape="circle">
									取消
								</u-button>
							</view>
						</view>
					</u-popup>
					<view
						style="width: 50px;height: 50px;float: left;margin: 41px 0px 0px 320px;">
						<uni-fab ref="fab" @fabClick="show = true" />
					</view>
				</view>
			</view>
			
		</view>
</template>

<script>
	import lFile from '@/uni_modules/l-file/components/l-file/l-file.vue'
	export default {
		data() {
			return {
				list: ['所有文档', '我的文档'],
				curNow: 0,
				show: false,
				archivesname: "",
				submitter: "",
				submitter1:'',
				fwd1:[],
				url1: '',
				mywd:[],
				name:'',
			}
		},
		// onShow() {
		// 	this.findMyWd();
		
		// },
		onLoad(res) {
			this.findMyWd()
			this.findallwd()
			// this.submitter=res.submitter1
			
		},
		methods: {
			aa(date){
							const dateTime = new Date(date)
							const YY = dateTime.getFullYear()
							const MM =
								dateTime.getMonth() + 1 < 10 ? '0' + (dateTime.getMonth() + 1) : dateTime.getMonth() + 1
							const DD =
								dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate()
							const hh =
								dateTime.getHours() < 10 ? '0' + dateTime.getHours() : dateTime.getHours()
							const mm =
								dateTime.getMinutes() < 10 ? '0' + dateTime.getMinutes() : dateTime.getMinutes()
							const ss =
								dateTime.getSeconds() < 10 ? '0' + dateTime.getSeconds() : dateTime.getSeconds()
							return `${YY}-${MM}-${DD}`
						},
			// 查看我的文档
			findMyWd(){
				var that = this
				uni.getStorage({
					key: "user",
					success: function(res) {
						that.liste1 = res.data;
					},
				});
				uni.request({
					url: 'http://localhost:9525/fragmentary/findMyWd?submitter='+this.liste1.name,
					method:'post',
					success: (res) => {
						this.mywd=res.data.data.data
					},
				});
			},
			// 预览
			wdtz(archivesname) {
				uni.navigateTo({
					url: "fileview?url=" + archivesname
				})
			},
			// 文档
			findallwd() {
				uni.request({
					url: 'http://localhost:9525/fragmentary/findallwd',
					method: 'post',
					success: (res) => {
						this.fwd1 = res.data.data.data
					}
				})
			},
			addWd(url1) {
				var that = this
				uni.getStorage({
					key: "user",
					success: function(res) {
						that.liste = res.data;
					},
				});
				uni.request({
					url: 'http://localhost:9525/fragmentary/addWD',
					method: 'POST',
					data: {
						archivesname: this.url1,
						submitter: this.liste.name,
					},
					dataType: 'json',
					success: (res) => {
						uni.showToast({
							title: "上传成功"
						})
					}
				})
				this.wdtz1();
			},
			wdtz1(){
				uni.navigateBack({
					delta:1
				})
			},
			
			onSuccess(res) {
				let m = this;
				console.log('上传成功回调=====33====', JSON.stringify(res));
				this.url1 = res.data;
				this.addWd(this.url1, this.submitter);
				uni.showToast({
					title: "上传成功",
					// title: JSON.stringify(res),
					icon: 'none',
					//  success: function (res) {
					// 	m.addWd(this.url1);
					// }
				});
				
			},
			onUpload() {
				this.$refs.lFile.upload({
					// #ifdef APP-PLUS
					currentWebview: this.$mp.page.$getAppWebview(),
					// #endif
					//非真实地址，记得更换
					url: 'http://localhost:9525/fragmentary/file/handelPic',
					//默认file,上传文件的key
					name: 'file',
					// header: {"Content-Type":"multipart/form-data; boundary=----WebKitFormBoundaryHEdN1AIjcdUkAaXM"},
					//...其他参数
				});
			},
		
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			sectionChange(index) {
				this.curNow = index;
			},
			search(res) {
				uni.showToast({
					title: '搜索：' + res.value,
					icon: 'none'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.button1 {
		width: 150px;
		margin-left: 10px;
		background: #2979ff;
		border-radius: 10px;
		border-color: #2979ff;
	}

	.button2 {
		float: left;
		color: #fa8e82;
		width: 150px;
		margin: -40px 0px 0px 165px;
		background: #ffffff;
		border-radius: 10px;
		border-color: #fcd4d2;

	}

	.butt1 {
		padding: 25px 0px 25px 0px;
		font-size: 18px;
		background-color: #ffffff;
		color: #3875f2;
		border-color: #f8f8f8;
		border-radius: 0px;
	}
</style>
